# scope_profiler.region_profiler

*module*

Profile region classes implementing the strategy pattern for different profiling modes.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L1-L1)

## scope_profiler.region_profiler.AggregateProfileRegion

*class*

```python
class AggregateProfileRegion
```

Low-memory region that records aggregate timing statistics only.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L193-L318)

### scope_profiler.region_profiler.AggregateProfileRegion.config

*attribute* · *instance attribute*

```python
config = config
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L215-L215)

### scope_profiler.region_profiler.AggregateProfileRegion.region_name

*attribute* · *instance attribute*

```python
region_name = region_name
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L214-L214)

### scope_profiler.region_profiler.AggregateProfileRegion.source_file

*attribute* · *instance attribute*

```python
source_file = None
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L217-L217)

### scope_profiler.region_profiler.AggregateProfileRegion.source_lineno

*attribute* · *instance attribute*

```python
source_lineno = None
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L217-L217)

### scope_profiler.region_profiler.AggregateProfileRegion.source_text

*attribute* · *instance attribute*

```python
source_text = None
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L217-L217)

### scope_profiler.region_profiler.AggregateProfileRegion.tags

*attribute* · *instance attribute*

```python
tags = tuple(tags)
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L216-L216)

### scope_profiler.region_profiler.AggregateProfileRegion.has_source

*property*

```python
has_source
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L236-L237)

### scope_profiler.region_profiler.AggregateProfileRegion.num_calls

*property*

```python
num_calls
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L232-L233)

### scope_profiler.region_profiler.AggregateProfileRegion.ptr

*property*

```python
ptr
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L228-L229)

### scope_profiler.region_profiler.AggregateProfileRegion.add_function

*method*

```python
def add_function(func)
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L247-L248)

### scope_profiler.region_profiler.AggregateProfileRegion.aggregate_snapshot

*method*

```python
def aggregate_snapshot()
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L305-L306)

### scope_profiler.region_profiler.AggregateProfileRegion.get_aggregate

*method*

```python
def get_aggregate()
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L250-L257)

### scope_profiler.region_profiler.AggregateProfileRegion.mark_written

*method*

```python
def mark_written()
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L300-L303)

### scope_profiler.region_profiler.AggregateProfileRegion.set_source

*method*

```python
def set_source(filename, lineno, text)
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L239-L245)

### scope_profiler.region_profiler.AggregateProfileRegion.wrap

*method*

```python
def wrap(func)
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L287-L298)

## scope_profiler.region_profiler.BaseProfileRegion

*class*

```python
class BaseProfileRegion
```

Base class providing shared profiling logic.

Handles start/end time buffering and call counting. The buffers grow on
demand and are copied out once, at the end of the run, by
``ProfileManager.finalize()`` - regions never touch HDF5 themselves.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L322-L593)

### scope_profiler.region_profiler.BaseProfileRegion.buffer_limit

*attribute* · *instance attribute*

```python
buffer_limit = config.buffer_limit
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L388-L388)

### scope_profiler.region_profiler.BaseProfileRegion.capacity

*attribute* · *instance attribute*

```python
capacity = self.buffer_limit
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L390-L390)

### scope_profiler.region_profiler.BaseProfileRegion.config

*attribute* · *instance attribute*

```python
config = config
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L366-L366)

### scope_profiler.region_profiler.BaseProfileRegion.end_times

*attribute* · *instance attribute*

```python
end_times = np.zeros(self.capacity, dtype=np.int64)
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L392-L392)

### scope_profiler.region_profiler.BaseProfileRegion.ptr

*attribute* · *instance attribute*

```python
ptr = 0
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L387-L387)

### scope_profiler.region_profiler.BaseProfileRegion.region_name

*attribute* · *instance attribute*

```python
region_name = region_name
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L365-L365)

### scope_profiler.region_profiler.BaseProfileRegion.source_file

*attribute* · *instance attribute*

```python
source_file = None
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L415-L415)

### scope_profiler.region_profiler.BaseProfileRegion.source_lineno

*attribute* · *instance attribute*

```python
source_lineno = None
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L416-L416)

### scope_profiler.region_profiler.BaseProfileRegion.source_text

*attribute* · *instance attribute*

```python
source_text = None
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L417-L417)

### scope_profiler.region_profiler.BaseProfileRegion.start_times

*attribute* · *instance attribute*

```python
start_times = np.empty(self.capacity, dtype=np.int64)
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L391-L391)

### scope_profiler.region_profiler.BaseProfileRegion.tags

*attribute* · *instance attribute*

```python
tags = tuple(tags)
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L367-L367)

### scope_profiler.region_profiler.BaseProfileRegion.has_source

*property*

```python
has_source: bool
```

Whether this region's call-site source was captured.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L433-L435)

### scope_profiler.region_profiler.BaseProfileRegion.num_calls

*property*

```python
num_calls: int
```

Times this region was entered, for the lifetime of the process.

Derived rather than counted: the slots in use (``ptr``) plus whatever
earlier finalize() calls already copied out. Keeping it out of
``__enter__`` removes an attribute write from every recorded call.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L489-L496)

### scope_profiler.region_profiler.BaseProfileRegion.add_function

*method*

```python
def add_function(func) -> None
```

Register a function for profiling. No-op except in LineProfilerRegion.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L592-L593)

### scope_profiler.region_profiler.BaseProfileRegion.append

*method*

```python
def append(start: float, end: float) -> None
```

Append a start/end time pair to the buffer, growing it if needed.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L479-L486)

### scope_profiler.region_profiler.BaseProfileRegion.closed_slots

*method*

```python
def closed_slots() -> np.ndarray | None
```

Mask of buffered slots this finalize() should copy out.

A slot qualifies once its end time is written and it has not already
gone out with an earlier finalize(). None - the usual case - means
every slot qualifies and the caller can skip the mask entirely.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L514-L526)

### scope_profiler.region_profiler.BaseProfileRegion.get_durations_numpy

*method*

```python
def get_durations_numpy() -> np.ndarray
```

Return durations (end - start) for buffered entries as a NumPy array.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L498-L500)

### scope_profiler.region_profiler.BaseProfileRegion.get_end_times_numpy

*method*

```python
def get_end_times_numpy() -> np.ndarray
```

Return end times offset by the run's start time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L584-L586)

### scope_profiler.region_profiler.BaseProfileRegion.get_start_times_numpy

*method*

```python
def get_start_times_numpy() -> np.ndarray
```

Return start times offset by the run's start time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L588-L590)

### scope_profiler.region_profiler.BaseProfileRegion.mark_written

*method*

```python
def mark_written() -> None
```

Record that everything buffered so far has been handed to finalize().

Called by ``finalize()`` once the data has been copied out, so that a
second run in the same process reports only its own events instead of
re-reporting the first run's. The timestamp buffer rewinds (the arrays
are reused; anything past ``ptr`` is unread scratch), while
``num_calls`` keeps counting for the lifetime of the process — it is
the in-memory view of the region, which callers inspect after
``finalize()``.

A call still running has a slot reserved that finalize() did not copy
out, so it must survive the rewind. It is moved to the front of the
buffer rather than pinning everything behind it: leaving the whole
buffer in place would make the next finalize() re-report every
completed call sitting below it, with a second set of call ids.

The one case that still cannot rewind is a call entered through the
decorator form, which keeps its slot index in the wrapper's own frame
where nothing can remap it. Recognisable because such a slot is open
without appearing in ``_scope_ptr_stack``. There the buffer stays put
and the slots already copied out are recorded instead, so the next
finalize() skips them rather than reporting those calls again.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L545-L582)

### scope_profiler.region_profiler.BaseProfileRegion.open_slots

*method*

```python
def open_slots() -> np.ndarray
```

Buffer slots whose call is still running, in ascending order.

A slot is open until its end time is written, which is what
distinguishes a call in flight from one that has returned. Both region
forms are covered: the context manager writes its start on entry, the
decorator writes nothing until the call returns.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L502-L512)

### scope_profiler.region_profiler.BaseProfileRegion.set_source

*method*

```python
def set_source(filename, lineno, text) -> None
```

Record where this region is defined, the first time it is called.

First writer wins: a region name reused at more than one call site
keeps only the first location, matching how their timings are already
pooled together under one name (see issue #161).

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L419-L430)

### scope_profiler.region_profiler.BaseProfileRegion.wrap

*method*

```python
def wrap(func)
```

Wrap a function for profiling.

Subclasses must override this method to implement the appropriate
profiling behavior.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L456-L467)

## scope_profiler.region_profiler.CUDATimingNVTXProfileRegion

*class*

```python
class CUDATimingNVTXProfileRegion(CUDATimingProfileRegion)
```

Bases: `scope_profiler.region_profiler.CUDATimingProfileRegion`

Region that records CPU/CUDA-event timing and emits an NVTX range.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L899-L948)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.gpu_durations

*attribute* · *instance attribute*

```python
gpu_durations = np.empty(self.capacity, dtype=np.int64)
```

Inherited from: `scope_profiler.region_profiler.CUDATimingProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L757-L757)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.buffer_limit

*attribute* · *instance attribute*

```python
buffer_limit = config.buffer_limit
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L388-L388)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.capacity

*attribute* · *instance attribute*

```python
capacity = self.buffer_limit
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L390-L390)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.config

*attribute* · *instance attribute*

```python
config = config
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L366-L366)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.end_times

*attribute* · *instance attribute*

```python
end_times = np.zeros(self.capacity, dtype=np.int64)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L392-L392)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.ptr

*attribute* · *instance attribute*

```python
ptr = 0
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L387-L387)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.region_name

*attribute* · *instance attribute*

```python
region_name = region_name
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L365-L365)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.source_file

*attribute* · *instance attribute*

```python
source_file = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L415-L415)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.source_lineno

*attribute* · *instance attribute*

```python
source_lineno = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L416-L416)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.source_text

*attribute* · *instance attribute*

```python
source_text = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L417-L417)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.start_times

*attribute* · *instance attribute*

```python
start_times = np.empty(self.capacity, dtype=np.int64)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L391-L391)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.tags

*attribute* · *instance attribute*

```python
tags = tuple(tags)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L367-L367)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.has_source

*property*

```python
has_source: bool
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Whether this region's call-site source was captured.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L433-L435)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.num_calls

*property*

```python
num_calls: int
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Times this region was entered, for the lifetime of the process.

Derived rather than counted: the slots in use (``ptr``) plus whatever
earlier finalize() calls already copied out. Keeping it out of
``__enter__`` removes an attribute write from every recorded call.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L489-L496)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.wrap

*method*

```python
def wrap(func)
```

Wrap a function with CPU/CUDA timing and an NVTX range.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L908-L922)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.get_gpu_durations_numpy

*method*

```python
def get_gpu_durations_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.CUDATimingProfileRegion`

Synchronize recorded CUDA events and return device durations in ns.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L805-L813)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.add_function

*method*

```python
def add_function(func) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Register a function for profiling. No-op except in LineProfilerRegion.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L592-L593)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.append

*method*

```python
def append(start: float, end: float) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Append a start/end time pair to the buffer, growing it if needed.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L479-L486)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.closed_slots

*method*

```python
def closed_slots() -> np.ndarray | None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Mask of buffered slots this finalize() should copy out.

A slot qualifies once its end time is written and it has not already
gone out with an earlier finalize(). None - the usual case - means
every slot qualifies and the caller can skip the mask entirely.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L514-L526)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.get_durations_numpy

*method*

```python
def get_durations_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return durations (end - start) for buffered entries as a NumPy array.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L498-L500)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.get_end_times_numpy

*method*

```python
def get_end_times_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return end times offset by the run's start time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L584-L586)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.get_start_times_numpy

*method*

```python
def get_start_times_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return start times offset by the run's start time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L588-L590)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.mark_written

*method*

```python
def mark_written() -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Record that everything buffered so far has been handed to finalize().

Called by ``finalize()`` once the data has been copied out, so that a
second run in the same process reports only its own events instead of
re-reporting the first run's. The timestamp buffer rewinds (the arrays
are reused; anything past ``ptr`` is unread scratch), while
``num_calls`` keeps counting for the lifetime of the process — it is
the in-memory view of the region, which callers inspect after
``finalize()``.

A call still running has a slot reserved that finalize() did not copy
out, so it must survive the rewind. It is moved to the front of the
buffer rather than pinning everything behind it: leaving the whole
buffer in place would make the next finalize() re-report every
completed call sitting below it, with a second set of call ids.

The one case that still cannot rewind is a call entered through the
decorator form, which keeps its slot index in the wrapper's own frame
where nothing can remap it. Recognisable because such a slot is open
without appearing in ``_scope_ptr_stack``. There the buffer stays put
and the slots already copied out are recorded instead, so the next
finalize() skips them rather than reporting those calls again.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L545-L582)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.open_slots

*method*

```python
def open_slots() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Buffer slots whose call is still running, in ascending order.

A slot is open until its end time is written, which is what
distinguishes a call in flight from one that has returned. Both region
forms are covered: the context manager writes its start on entry, the
decorator writes nothing until the call returns.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L502-L512)

### scope_profiler.region_profiler.CUDATimingNVTXProfileRegion.set_source

*method*

```python
def set_source(filename, lineno, text) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Record where this region is defined, the first time it is called.

First writer wins: a region name reused at more than one call site
keeps only the first location, matching how their timings are already
pooled together under one name (see issue #161).

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L419-L430)

## scope_profiler.region_profiler.CUDATimingProfileRegion

*class*

```python
class CUDATimingProfileRegion(TimeOnlyProfileRegion)
```

Bases: `scope_profiler.region_profiler.TimeOnlyProfileRegion`

Region that records CPU timing plus CUDA-event elapsed device time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L738-L837)

### scope_profiler.region_profiler.CUDATimingProfileRegion.gpu_durations

*attribute* · *instance attribute*

```python
gpu_durations = np.empty(self.capacity, dtype=np.int64)
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L757-L757)

### scope_profiler.region_profiler.CUDATimingProfileRegion.buffer_limit

*attribute* · *instance attribute*

```python
buffer_limit = config.buffer_limit
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L388-L388)

### scope_profiler.region_profiler.CUDATimingProfileRegion.capacity

*attribute* · *instance attribute*

```python
capacity = self.buffer_limit
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L390-L390)

### scope_profiler.region_profiler.CUDATimingProfileRegion.config

*attribute* · *instance attribute*

```python
config = config
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L366-L366)

### scope_profiler.region_profiler.CUDATimingProfileRegion.end_times

*attribute* · *instance attribute*

```python
end_times = np.zeros(self.capacity, dtype=np.int64)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L392-L392)

### scope_profiler.region_profiler.CUDATimingProfileRegion.ptr

*attribute* · *instance attribute*

```python
ptr = 0
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L387-L387)

### scope_profiler.region_profiler.CUDATimingProfileRegion.region_name

*attribute* · *instance attribute*

```python
region_name = region_name
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L365-L365)

### scope_profiler.region_profiler.CUDATimingProfileRegion.source_file

*attribute* · *instance attribute*

```python
source_file = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L415-L415)

### scope_profiler.region_profiler.CUDATimingProfileRegion.source_lineno

*attribute* · *instance attribute*

```python
source_lineno = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L416-L416)

### scope_profiler.region_profiler.CUDATimingProfileRegion.source_text

*attribute* · *instance attribute*

```python
source_text = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L417-L417)

### scope_profiler.region_profiler.CUDATimingProfileRegion.start_times

*attribute* · *instance attribute*

```python
start_times = np.empty(self.capacity, dtype=np.int64)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L391-L391)

### scope_profiler.region_profiler.CUDATimingProfileRegion.tags

*attribute* · *instance attribute*

```python
tags = tuple(tags)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L367-L367)

### scope_profiler.region_profiler.CUDATimingProfileRegion.has_source

*property*

```python
has_source: bool
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Whether this region's call-site source was captured.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L433-L435)

### scope_profiler.region_profiler.CUDATimingProfileRegion.num_calls

*property*

```python
num_calls: int
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Times this region was entered, for the lifetime of the process.

Derived rather than counted: the slots in use (``ptr``) plus whatever
earlier finalize() calls already copied out. Keeping it out of
``__enter__`` removes an attribute write from every recorded call.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L489-L496)

### scope_profiler.region_profiler.CUDATimingProfileRegion.get_gpu_durations_numpy

*method*

```python
def get_gpu_durations_numpy() -> np.ndarray
```

Synchronize recorded CUDA events and return device durations in ns.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L805-L813)

### scope_profiler.region_profiler.CUDATimingProfileRegion.wrap

*method*

```python
def wrap(func)
```

Wrap a function to measure CPU enqueue time and device elapsed time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L768-L791)

### scope_profiler.region_profiler.CUDATimingProfileRegion.add_function

*method*

```python
def add_function(func) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Register a function for profiling. No-op except in LineProfilerRegion.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L592-L593)

### scope_profiler.region_profiler.CUDATimingProfileRegion.append

*method*

```python
def append(start: float, end: float) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Append a start/end time pair to the buffer, growing it if needed.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L479-L486)

### scope_profiler.region_profiler.CUDATimingProfileRegion.closed_slots

*method*

```python
def closed_slots() -> np.ndarray | None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Mask of buffered slots this finalize() should copy out.

A slot qualifies once its end time is written and it has not already
gone out with an earlier finalize(). None - the usual case - means
every slot qualifies and the caller can skip the mask entirely.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L514-L526)

### scope_profiler.region_profiler.CUDATimingProfileRegion.get_durations_numpy

*method*

```python
def get_durations_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return durations (end - start) for buffered entries as a NumPy array.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L498-L500)

### scope_profiler.region_profiler.CUDATimingProfileRegion.get_end_times_numpy

*method*

```python
def get_end_times_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return end times offset by the run's start time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L584-L586)

### scope_profiler.region_profiler.CUDATimingProfileRegion.get_start_times_numpy

*method*

```python
def get_start_times_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return start times offset by the run's start time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L588-L590)

### scope_profiler.region_profiler.CUDATimingProfileRegion.mark_written

*method*

```python
def mark_written() -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Record that everything buffered so far has been handed to finalize().

Called by ``finalize()`` once the data has been copied out, so that a
second run in the same process reports only its own events instead of
re-reporting the first run's. The timestamp buffer rewinds (the arrays
are reused; anything past ``ptr`` is unread scratch), while
``num_calls`` keeps counting for the lifetime of the process — it is
the in-memory view of the region, which callers inspect after
``finalize()``.

A call still running has a slot reserved that finalize() did not copy
out, so it must survive the rewind. It is moved to the front of the
buffer rather than pinning everything behind it: leaving the whole
buffer in place would make the next finalize() re-report every
completed call sitting below it, with a second set of call ids.

The one case that still cannot rewind is a call entered through the
decorator form, which keeps its slot index in the wrapper's own frame
where nothing can remap it. Recognisable because such a slot is open
without appearing in ``_scope_ptr_stack``. There the buffer stays put
and the slots already copied out are recorded instead, so the next
finalize() skips them rather than reporting those calls again.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L545-L582)

### scope_profiler.region_profiler.CUDATimingProfileRegion.open_slots

*method*

```python
def open_slots() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Buffer slots whose call is still running, in ascending order.

A slot is open until its end time is written, which is what
distinguishes a call in flight from one that has returned. Both region
forms are covered: the context manager writes its start on entry, the
decorator writes nothing until the call returns.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L502-L512)

### scope_profiler.region_profiler.CUDATimingProfileRegion.set_source

*method*

```python
def set_source(filename, lineno, text) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Record where this region is defined, the first time it is called.

First writer wins: a region name reused at more than one call site
keeps only the first location, matching how their timings are already
pooled together under one name (see issue #161).

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L419-L430)

## scope_profiler.region_profiler.DisabledProfileRegion

*class*

```python
class DisabledProfileRegion(BaseProfileRegion)
```

Bases: `scope_profiler.region_profiler.BaseProfileRegion`

Profiling region that performs no measurements.

Used when profiling is disabled but code paths must remain valid.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L597-L621)

### scope_profiler.region_profiler.DisabledProfileRegion.buffer_limit

*attribute* · *instance attribute*

```python
buffer_limit = config.buffer_limit
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L388-L388)

### scope_profiler.region_profiler.DisabledProfileRegion.capacity

*attribute* · *instance attribute*

```python
capacity = self.buffer_limit
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L390-L390)

### scope_profiler.region_profiler.DisabledProfileRegion.config

*attribute* · *instance attribute*

```python
config = config
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L366-L366)

### scope_profiler.region_profiler.DisabledProfileRegion.end_times

*attribute* · *instance attribute*

```python
end_times = np.zeros(self.capacity, dtype=np.int64)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L392-L392)

### scope_profiler.region_profiler.DisabledProfileRegion.ptr

*attribute* · *instance attribute*

```python
ptr = 0
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L387-L387)

### scope_profiler.region_profiler.DisabledProfileRegion.region_name

*attribute* · *instance attribute*

```python
region_name = region_name
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L365-L365)

### scope_profiler.region_profiler.DisabledProfileRegion.source_file

*attribute* · *instance attribute*

```python
source_file = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L415-L415)

### scope_profiler.region_profiler.DisabledProfileRegion.source_lineno

*attribute* · *instance attribute*

```python
source_lineno = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L416-L416)

### scope_profiler.region_profiler.DisabledProfileRegion.source_text

*attribute* · *instance attribute*

```python
source_text = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L417-L417)

### scope_profiler.region_profiler.DisabledProfileRegion.start_times

*attribute* · *instance attribute*

```python
start_times = np.empty(self.capacity, dtype=np.int64)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L391-L391)

### scope_profiler.region_profiler.DisabledProfileRegion.tags

*attribute* · *instance attribute*

```python
tags = tuple(tags)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L367-L367)

### scope_profiler.region_profiler.DisabledProfileRegion.has_source

*property*

```python
has_source: bool
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Whether this region's call-site source was captured.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L433-L435)

### scope_profiler.region_profiler.DisabledProfileRegion.num_calls

*property*

```python
num_calls: int
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Times this region was entered, for the lifetime of the process.

Derived rather than counted: the slots in use (``ptr``) plus whatever
earlier finalize() calls already copied out. Keeping it out of
``__enter__`` removes an attribute write from every recorded call.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L489-L496)

### scope_profiler.region_profiler.DisabledProfileRegion.append

*method*

```python
def append(start, end)
```

Ignored: no data recorded.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L609-L610)

### scope_profiler.region_profiler.DisabledProfileRegion.get_durations_numpy

*method*

```python
def get_durations_numpy()
```

Return an empty array since nothing is recorded.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L612-L614)

### scope_profiler.region_profiler.DisabledProfileRegion.wrap

*method*

```python
def wrap(func)
```

Return the original function unchanged — no wrapper, no overhead.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L605-L607)

### scope_profiler.region_profiler.DisabledProfileRegion.add_function

*method*

```python
def add_function(func) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Register a function for profiling. No-op except in LineProfilerRegion.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L592-L593)

### scope_profiler.region_profiler.DisabledProfileRegion.closed_slots

*method*

```python
def closed_slots() -> np.ndarray | None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Mask of buffered slots this finalize() should copy out.

A slot qualifies once its end time is written and it has not already
gone out with an earlier finalize(). None - the usual case - means
every slot qualifies and the caller can skip the mask entirely.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L514-L526)

### scope_profiler.region_profiler.DisabledProfileRegion.get_end_times_numpy

*method*

```python
def get_end_times_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return end times offset by the run's start time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L584-L586)

### scope_profiler.region_profiler.DisabledProfileRegion.get_start_times_numpy

*method*

```python
def get_start_times_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return start times offset by the run's start time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L588-L590)

### scope_profiler.region_profiler.DisabledProfileRegion.mark_written

*method*

```python
def mark_written() -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Record that everything buffered so far has been handed to finalize().

Called by ``finalize()`` once the data has been copied out, so that a
second run in the same process reports only its own events instead of
re-reporting the first run's. The timestamp buffer rewinds (the arrays
are reused; anything past ``ptr`` is unread scratch), while
``num_calls`` keeps counting for the lifetime of the process — it is
the in-memory view of the region, which callers inspect after
``finalize()``.

A call still running has a slot reserved that finalize() did not copy
out, so it must survive the rewind. It is moved to the front of the
buffer rather than pinning everything behind it: leaving the whole
buffer in place would make the next finalize() re-report every
completed call sitting below it, with a second set of call ids.

The one case that still cannot rewind is a call entered through the
decorator form, which keeps its slot index in the wrapper's own frame
where nothing can remap it. Recognisable because such a slot is open
without appearing in ``_scope_ptr_stack``. There the buffer stays put
and the slots already copied out are recorded instead, so the next
finalize() skips them rather than reporting those calls again.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L545-L582)

### scope_profiler.region_profiler.DisabledProfileRegion.open_slots

*method*

```python
def open_slots() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Buffer slots whose call is still running, in ascending order.

A slot is open until its end time is written, which is what
distinguishes a call in flight from one that has returned. Both region
forms are covered: the context manager writes its start on entry, the
decorator writes nothing until the call returns.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L502-L512)

### scope_profiler.region_profiler.DisabledProfileRegion.set_source

*method*

```python
def set_source(filename, lineno, text) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Record where this region is defined, the first time it is called.

First writer wins: a region name reused at more than one call site
keeps only the first location, matching how their timings are already
pooled together under one name (see issue #161).

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L419-L430)

## scope_profiler.region_profiler.FullProfileRegion

*class*

```python
class FullProfileRegion(BaseProfileRegion)
```

Bases: `scope_profiler.region_profiler.BaseProfileRegion`

Region that records both timing and LIKWID metrics, and writes to HDF5.

This is the most complete profiling mode: users obtain LIKWID markers and
nanosecond-resolution timing.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L952-L1013)

### scope_profiler.region_profiler.FullProfileRegion.likwid_marker_start

*attribute* · *instance attribute*

```python
likwid_marker_start = pylikwid.markerstartregion
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L965-L965)

### scope_profiler.region_profiler.FullProfileRegion.likwid_marker_stop

*attribute* · *instance attribute*

```python
likwid_marker_stop = pylikwid.markerstopregion
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L966-L966)

### scope_profiler.region_profiler.FullProfileRegion.buffer_limit

*attribute* · *instance attribute*

```python
buffer_limit = config.buffer_limit
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L388-L388)

### scope_profiler.region_profiler.FullProfileRegion.capacity

*attribute* · *instance attribute*

```python
capacity = self.buffer_limit
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L390-L390)

### scope_profiler.region_profiler.FullProfileRegion.config

*attribute* · *instance attribute*

```python
config = config
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L366-L366)

### scope_profiler.region_profiler.FullProfileRegion.end_times

*attribute* · *instance attribute*

```python
end_times = np.zeros(self.capacity, dtype=np.int64)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L392-L392)

### scope_profiler.region_profiler.FullProfileRegion.ptr

*attribute* · *instance attribute*

```python
ptr = 0
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L387-L387)

### scope_profiler.region_profiler.FullProfileRegion.region_name

*attribute* · *instance attribute*

```python
region_name = region_name
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L365-L365)

### scope_profiler.region_profiler.FullProfileRegion.source_file

*attribute* · *instance attribute*

```python
source_file = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L415-L415)

### scope_profiler.region_profiler.FullProfileRegion.source_lineno

*attribute* · *instance attribute*

```python
source_lineno = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L416-L416)

### scope_profiler.region_profiler.FullProfileRegion.source_text

*attribute* · *instance attribute*

```python
source_text = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L417-L417)

### scope_profiler.region_profiler.FullProfileRegion.start_times

*attribute* · *instance attribute*

```python
start_times = np.empty(self.capacity, dtype=np.int64)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L391-L391)

### scope_profiler.region_profiler.FullProfileRegion.tags

*attribute* · *instance attribute*

```python
tags = tuple(tags)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L367-L367)

### scope_profiler.region_profiler.FullProfileRegion.has_source

*property*

```python
has_source: bool
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Whether this region's call-site source was captured.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L433-L435)

### scope_profiler.region_profiler.FullProfileRegion.num_calls

*property*

```python
num_calls: int
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Times this region was entered, for the lifetime of the process.

Derived rather than counted: the slots in use (``ptr``) plus whatever
earlier finalize() calls already copied out. Keeping it out of
``__enter__`` removes an attribute write from every recorded call.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L489-L496)

### scope_profiler.region_profiler.FullProfileRegion.wrap

*method*

```python
def wrap(func)
```

Wrap a function to measure time and collect LIKWID metrics.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L968-L992)

### scope_profiler.region_profiler.FullProfileRegion.add_function

*method*

```python
def add_function(func) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Register a function for profiling. No-op except in LineProfilerRegion.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L592-L593)

### scope_profiler.region_profiler.FullProfileRegion.append

*method*

```python
def append(start: float, end: float) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Append a start/end time pair to the buffer, growing it if needed.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L479-L486)

### scope_profiler.region_profiler.FullProfileRegion.closed_slots

*method*

```python
def closed_slots() -> np.ndarray | None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Mask of buffered slots this finalize() should copy out.

A slot qualifies once its end time is written and it has not already
gone out with an earlier finalize(). None - the usual case - means
every slot qualifies and the caller can skip the mask entirely.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L514-L526)

### scope_profiler.region_profiler.FullProfileRegion.get_durations_numpy

*method*

```python
def get_durations_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return durations (end - start) for buffered entries as a NumPy array.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L498-L500)

### scope_profiler.region_profiler.FullProfileRegion.get_end_times_numpy

*method*

```python
def get_end_times_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return end times offset by the run's start time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L584-L586)

### scope_profiler.region_profiler.FullProfileRegion.get_start_times_numpy

*method*

```python
def get_start_times_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return start times offset by the run's start time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L588-L590)

### scope_profiler.region_profiler.FullProfileRegion.mark_written

*method*

```python
def mark_written() -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Record that everything buffered so far has been handed to finalize().

Called by ``finalize()`` once the data has been copied out, so that a
second run in the same process reports only its own events instead of
re-reporting the first run's. The timestamp buffer rewinds (the arrays
are reused; anything past ``ptr`` is unread scratch), while
``num_calls`` keeps counting for the lifetime of the process — it is
the in-memory view of the region, which callers inspect after
``finalize()``.

A call still running has a slot reserved that finalize() did not copy
out, so it must survive the rewind. It is moved to the front of the
buffer rather than pinning everything behind it: leaving the whole
buffer in place would make the next finalize() re-report every
completed call sitting below it, with a second set of call ids.

The one case that still cannot rewind is a call entered through the
decorator form, which keeps its slot index in the wrapper's own frame
where nothing can remap it. Recognisable because such a slot is open
without appearing in ``_scope_ptr_stack``. There the buffer stays put
and the slots already copied out are recorded instead, so the next
finalize() skips them rather than reporting those calls again.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L545-L582)

### scope_profiler.region_profiler.FullProfileRegion.open_slots

*method*

```python
def open_slots() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Buffer slots whose call is still running, in ascending order.

A slot is open until its end time is written, which is what
distinguishes a call in flight from one that has returned. Both region
forms are covered: the context manager writes its start on entry, the
decorator writes nothing until the call returns.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L502-L512)

### scope_profiler.region_profiler.FullProfileRegion.set_source

*method*

```python
def set_source(filename, lineno, text) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Record where this region is defined, the first time it is called.

First writer wins: a region name reused at more than one call site
keeps only the first location, matching how their timings are already
pooled together under one name (see issue #161).

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L419-L430)

## scope_profiler.region_profiler.LineProfilerRegion

*class*

```python
class LineProfilerRegion(BaseProfileRegion)
```

Bases: `scope_profiler.region_profiler.BaseProfileRegion`

Region that records timing and line-by-line profiling via line_profiler.

Uses line_profiler to collect per-line execution statistics for decorated
functions. Also records nanosecond timestamps.

Line-by-line profiling is most useful with the decorator (``wrap``) path,
which automatically registers the function with the line profiler.  When
used as a context manager, the profiler is enabled/disabled around the
block - any functions previously added via the decorator path will be
profiled while the context is active.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L1017-L1156)

### scope_profiler.region_profiler.LineProfilerRegion.buffer_limit

*attribute* · *instance attribute*

```python
buffer_limit = config.buffer_limit
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L388-L388)

### scope_profiler.region_profiler.LineProfilerRegion.capacity

*attribute* · *instance attribute*

```python
capacity = self.buffer_limit
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L390-L390)

### scope_profiler.region_profiler.LineProfilerRegion.config

*attribute* · *instance attribute*

```python
config = config
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L366-L366)

### scope_profiler.region_profiler.LineProfilerRegion.end_times

*attribute* · *instance attribute*

```python
end_times = np.zeros(self.capacity, dtype=np.int64)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L392-L392)

### scope_profiler.region_profiler.LineProfilerRegion.ptr

*attribute* · *instance attribute*

```python
ptr = 0
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L387-L387)

### scope_profiler.region_profiler.LineProfilerRegion.region_name

*attribute* · *instance attribute*

```python
region_name = region_name
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L365-L365)

### scope_profiler.region_profiler.LineProfilerRegion.source_file

*attribute* · *instance attribute*

```python
source_file = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L415-L415)

### scope_profiler.region_profiler.LineProfilerRegion.source_lineno

*attribute* · *instance attribute*

```python
source_lineno = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L416-L416)

### scope_profiler.region_profiler.LineProfilerRegion.source_text

*attribute* · *instance attribute*

```python
source_text = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L417-L417)

### scope_profiler.region_profiler.LineProfilerRegion.start_times

*attribute* · *instance attribute*

```python
start_times = np.empty(self.capacity, dtype=np.int64)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L391-L391)

### scope_profiler.region_profiler.LineProfilerRegion.tags

*attribute* · *instance attribute*

```python
tags = tuple(tags)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L367-L367)

### scope_profiler.region_profiler.LineProfilerRegion.has_source

*property*

```python
has_source: bool
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Whether this region's call-site source was captured.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L433-L435)

### scope_profiler.region_profiler.LineProfilerRegion.num_calls

*property*

```python
num_calls: int
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Times this region was entered, for the lifetime of the process.

Derived rather than counted: the slots in use (``ptr``) plus whatever
earlier finalize() calls already copied out. Keeping it out of
``__enter__`` removes an attribute write from every recorded call.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L489-L496)

### scope_profiler.region_profiler.LineProfilerRegion.add_function

*method*

```python
def add_function(func) -> None
```

Register a function for line-by-line profiling.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L1135-L1137)

### scope_profiler.region_profiler.LineProfilerRegion.enter_frame

*method*

```python
def enter_frame(frame)
```

Enter this region while registering ``frame`` with line_profiler.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L1067-L1084)

### scope_profiler.region_profiler.LineProfilerRegion.enter_timing_only

*method*

```python
def enter_timing_only()
```

Enter this region without registering or enabling line_profiler.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L1086-L1097)

### scope_profiler.region_profiler.LineProfilerRegion.get_stats

*method*

```python
def get_stats()
```

Return the line_profiler stats object.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L1143-L1145)

### scope_profiler.region_profiler.LineProfilerRegion.manual_line_records

*method*

```python
def manual_line_records(unit: float = 1e-09) -> list
```

Return manually traced line timings in the persisted record shape.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L1113-L1133)

### scope_profiler.region_profiler.LineProfilerRegion.print_stats

*method*

```python
def print_stats()
```

Print line-by-line profiling statistics.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L1139-L1141)

### scope_profiler.region_profiler.LineProfilerRegion.record_line_timing

*method*

```python
def record_line_timing(frame, lineno: int, duration_ns: int) -> None
```

Record one line timing sample from recursive CLI tracing.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L1099-L1111)

### scope_profiler.region_profiler.LineProfilerRegion.wrap

*method*

```python
def wrap(func)
```

Wrap a function to measure execution time and collect line-by-line stats.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L1040-L1065)

### scope_profiler.region_profiler.LineProfilerRegion.append

*method*

```python
def append(start: float, end: float) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Append a start/end time pair to the buffer, growing it if needed.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L479-L486)

### scope_profiler.region_profiler.LineProfilerRegion.closed_slots

*method*

```python
def closed_slots() -> np.ndarray | None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Mask of buffered slots this finalize() should copy out.

A slot qualifies once its end time is written and it has not already
gone out with an earlier finalize(). None - the usual case - means
every slot qualifies and the caller can skip the mask entirely.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L514-L526)

### scope_profiler.region_profiler.LineProfilerRegion.get_durations_numpy

*method*

```python
def get_durations_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return durations (end - start) for buffered entries as a NumPy array.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L498-L500)

### scope_profiler.region_profiler.LineProfilerRegion.get_end_times_numpy

*method*

```python
def get_end_times_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return end times offset by the run's start time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L584-L586)

### scope_profiler.region_profiler.LineProfilerRegion.get_start_times_numpy

*method*

```python
def get_start_times_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return start times offset by the run's start time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L588-L590)

### scope_profiler.region_profiler.LineProfilerRegion.mark_written

*method*

```python
def mark_written() -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Record that everything buffered so far has been handed to finalize().

Called by ``finalize()`` once the data has been copied out, so that a
second run in the same process reports only its own events instead of
re-reporting the first run's. The timestamp buffer rewinds (the arrays
are reused; anything past ``ptr`` is unread scratch), while
``num_calls`` keeps counting for the lifetime of the process — it is
the in-memory view of the region, which callers inspect after
``finalize()``.

A call still running has a slot reserved that finalize() did not copy
out, so it must survive the rewind. It is moved to the front of the
buffer rather than pinning everything behind it: leaving the whole
buffer in place would make the next finalize() re-report every
completed call sitting below it, with a second set of call ids.

The one case that still cannot rewind is a call entered through the
decorator form, which keeps its slot index in the wrapper's own frame
where nothing can remap it. Recognisable because such a slot is open
without appearing in ``_scope_ptr_stack``. There the buffer stays put
and the slots already copied out are recorded instead, so the next
finalize() skips them rather than reporting those calls again.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L545-L582)

### scope_profiler.region_profiler.LineProfilerRegion.open_slots

*method*

```python
def open_slots() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Buffer slots whose call is still running, in ascending order.

A slot is open until its end time is written, which is what
distinguishes a call in flight from one that has returned. Both region
forms are covered: the context manager writes its start on entry, the
decorator writes nothing until the call returns.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L502-L512)

### scope_profiler.region_profiler.LineProfilerRegion.set_source

*method*

```python
def set_source(filename, lineno, text) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Record where this region is defined, the first time it is called.

First writer wins: a region name reused at more than one call site
keeps only the first location, matching how their timings are already
pooled together under one name (see issue #161).

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L419-L430)

## scope_profiler.region_profiler.NVTXProfileRegion

*class*

```python
class NVTXProfileRegion(TimeOnlyProfileRegion)
```

Bases: `scope_profiler.region_profiler.TimeOnlyProfileRegion`

Region that records CPU time and emits an NVTX range.

NVTX is an annotation API, not a GPU timing API. Nsight Systems and
Nsight Compute consume the ranges and correlate them with GPU work. The
normal CPU timestamps are retained in the scope-profiler result.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L841-L896)

### scope_profiler.region_profiler.NVTXProfileRegion.buffer_limit

*attribute* · *instance attribute*

```python
buffer_limit = config.buffer_limit
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L388-L388)

### scope_profiler.region_profiler.NVTXProfileRegion.capacity

*attribute* · *instance attribute*

```python
capacity = self.buffer_limit
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L390-L390)

### scope_profiler.region_profiler.NVTXProfileRegion.config

*attribute* · *instance attribute*

```python
config = config
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L366-L366)

### scope_profiler.region_profiler.NVTXProfileRegion.end_times

*attribute* · *instance attribute*

```python
end_times = np.zeros(self.capacity, dtype=np.int64)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L392-L392)

### scope_profiler.region_profiler.NVTXProfileRegion.ptr

*attribute* · *instance attribute*

```python
ptr = 0
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L387-L387)

### scope_profiler.region_profiler.NVTXProfileRegion.region_name

*attribute* · *instance attribute*

```python
region_name = region_name
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L365-L365)

### scope_profiler.region_profiler.NVTXProfileRegion.source_file

*attribute* · *instance attribute*

```python
source_file = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L415-L415)

### scope_profiler.region_profiler.NVTXProfileRegion.source_lineno

*attribute* · *instance attribute*

```python
source_lineno = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L416-L416)

### scope_profiler.region_profiler.NVTXProfileRegion.source_text

*attribute* · *instance attribute*

```python
source_text = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L417-L417)

### scope_profiler.region_profiler.NVTXProfileRegion.start_times

*attribute* · *instance attribute*

```python
start_times = np.empty(self.capacity, dtype=np.int64)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L391-L391)

### scope_profiler.region_profiler.NVTXProfileRegion.tags

*attribute* · *instance attribute*

```python
tags = tuple(tags)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L367-L367)

### scope_profiler.region_profiler.NVTXProfileRegion.has_source

*property*

```python
has_source: bool
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Whether this region's call-site source was captured.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L433-L435)

### scope_profiler.region_profiler.NVTXProfileRegion.num_calls

*property*

```python
num_calls: int
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Times this region was entered, for the lifetime of the process.

Derived rather than counted: the slots in use (``ptr``) plus whatever
earlier finalize() calls already copied out. Keeping it out of
``__enter__`` removes an attribute write from every recorded call.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L489-L496)

### scope_profiler.region_profiler.NVTXProfileRegion.wrap

*method*

```python
def wrap(func)
```

Wrap a function with both CPU timing and an NVTX range.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L855-L869)

### scope_profiler.region_profiler.NVTXProfileRegion.add_function

*method*

```python
def add_function(func) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Register a function for profiling. No-op except in LineProfilerRegion.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L592-L593)

### scope_profiler.region_profiler.NVTXProfileRegion.append

*method*

```python
def append(start: float, end: float) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Append a start/end time pair to the buffer, growing it if needed.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L479-L486)

### scope_profiler.region_profiler.NVTXProfileRegion.closed_slots

*method*

```python
def closed_slots() -> np.ndarray | None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Mask of buffered slots this finalize() should copy out.

A slot qualifies once its end time is written and it has not already
gone out with an earlier finalize(). None - the usual case - means
every slot qualifies and the caller can skip the mask entirely.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L514-L526)

### scope_profiler.region_profiler.NVTXProfileRegion.get_durations_numpy

*method*

```python
def get_durations_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return durations (end - start) for buffered entries as a NumPy array.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L498-L500)

### scope_profiler.region_profiler.NVTXProfileRegion.get_end_times_numpy

*method*

```python
def get_end_times_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return end times offset by the run's start time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L584-L586)

### scope_profiler.region_profiler.NVTXProfileRegion.get_start_times_numpy

*method*

```python
def get_start_times_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return start times offset by the run's start time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L588-L590)

### scope_profiler.region_profiler.NVTXProfileRegion.mark_written

*method*

```python
def mark_written() -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Record that everything buffered so far has been handed to finalize().

Called by ``finalize()`` once the data has been copied out, so that a
second run in the same process reports only its own events instead of
re-reporting the first run's. The timestamp buffer rewinds (the arrays
are reused; anything past ``ptr`` is unread scratch), while
``num_calls`` keeps counting for the lifetime of the process — it is
the in-memory view of the region, which callers inspect after
``finalize()``.

A call still running has a slot reserved that finalize() did not copy
out, so it must survive the rewind. It is moved to the front of the
buffer rather than pinning everything behind it: leaving the whole
buffer in place would make the next finalize() re-report every
completed call sitting below it, with a second set of call ids.

The one case that still cannot rewind is a call entered through the
decorator form, which keeps its slot index in the wrapper's own frame
where nothing can remap it. Recognisable because such a slot is open
without appearing in ``_scope_ptr_stack``. There the buffer stays put
and the slots already copied out are recorded instead, so the next
finalize() skips them rather than reporting those calls again.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L545-L582)

### scope_profiler.region_profiler.NVTXProfileRegion.open_slots

*method*

```python
def open_slots() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Buffer slots whose call is still running, in ascending order.

A slot is open until its end time is written, which is what
distinguishes a call in flight from one that has returned. Both region
forms are covered: the context manager writes its start on entry, the
decorator writes nothing until the call returns.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L502-L512)

### scope_profiler.region_profiler.NVTXProfileRegion.set_source

*method*

```python
def set_source(filename, lineno, text) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Record where this region is defined, the first time it is called.

First writer wins: a region name reused at more than one call site
keeps only the first location, matching how their timings are already
pooled together under one name (see issue #161).

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L419-L430)

## scope_profiler.region_profiler.PerfEventProfileRegion

*class*

```python
class PerfEventProfileRegion(TimeOnlyProfileRegion)
```

Bases: `scope_profiler.region_profiler.TimeOnlyProfileRegion`

Timing region which also sums Linux ``perf_event_open`` counters.

Counters are opened per active invocation. This makes nested and recursive
regions correct without sharing a mutable counter state, at the intended
cost of an extra kernel round trip per selected event.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L672-L735)

### scope_profiler.region_profiler.PerfEventProfileRegion.buffer_limit

*attribute* · *instance attribute*

```python
buffer_limit = config.buffer_limit
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L388-L388)

### scope_profiler.region_profiler.PerfEventProfileRegion.capacity

*attribute* · *instance attribute*

```python
capacity = self.buffer_limit
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L390-L390)

### scope_profiler.region_profiler.PerfEventProfileRegion.config

*attribute* · *instance attribute*

```python
config = config
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L366-L366)

### scope_profiler.region_profiler.PerfEventProfileRegion.end_times

*attribute* · *instance attribute*

```python
end_times = np.zeros(self.capacity, dtype=np.int64)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L392-L392)

### scope_profiler.region_profiler.PerfEventProfileRegion.ptr

*attribute* · *instance attribute*

```python
ptr = 0
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L387-L387)

### scope_profiler.region_profiler.PerfEventProfileRegion.region_name

*attribute* · *instance attribute*

```python
region_name = region_name
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L365-L365)

### scope_profiler.region_profiler.PerfEventProfileRegion.source_file

*attribute* · *instance attribute*

```python
source_file = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L415-L415)

### scope_profiler.region_profiler.PerfEventProfileRegion.source_lineno

*attribute* · *instance attribute*

```python
source_lineno = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L416-L416)

### scope_profiler.region_profiler.PerfEventProfileRegion.source_text

*attribute* · *instance attribute*

```python
source_text = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L417-L417)

### scope_profiler.region_profiler.PerfEventProfileRegion.start_times

*attribute* · *instance attribute*

```python
start_times = np.empty(self.capacity, dtype=np.int64)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L391-L391)

### scope_profiler.region_profiler.PerfEventProfileRegion.tags

*attribute* · *instance attribute*

```python
tags = tuple(tags)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L367-L367)

### scope_profiler.region_profiler.PerfEventProfileRegion.has_source

*property*

```python
has_source: bool
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Whether this region's call-site source was captured.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L433-L435)

### scope_profiler.region_profiler.PerfEventProfileRegion.num_calls

*property*

```python
num_calls: int
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Times this region was entered, for the lifetime of the process.

Derived rather than counted: the slots in use (``ptr``) plus whatever
earlier finalize() calls already copied out. Keeping it out of
``__enter__`` removes an attribute write from every recorded call.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L489-L496)

### scope_profiler.region_profiler.PerfEventProfileRegion.perf_event_totals

*method*

```python
def perf_event_totals() -> PerfEventTotals
```

Counter totals accumulated by completed calls in this region.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L697-L699)

### scope_profiler.region_profiler.PerfEventProfileRegion.wrap

*method*

```python
def wrap(func)
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L701-L714)

### scope_profiler.region_profiler.PerfEventProfileRegion.add_function

*method*

```python
def add_function(func) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Register a function for profiling. No-op except in LineProfilerRegion.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L592-L593)

### scope_profiler.region_profiler.PerfEventProfileRegion.append

*method*

```python
def append(start: float, end: float) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Append a start/end time pair to the buffer, growing it if needed.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L479-L486)

### scope_profiler.region_profiler.PerfEventProfileRegion.closed_slots

*method*

```python
def closed_slots() -> np.ndarray | None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Mask of buffered slots this finalize() should copy out.

A slot qualifies once its end time is written and it has not already
gone out with an earlier finalize(). None - the usual case - means
every slot qualifies and the caller can skip the mask entirely.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L514-L526)

### scope_profiler.region_profiler.PerfEventProfileRegion.get_durations_numpy

*method*

```python
def get_durations_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return durations (end - start) for buffered entries as a NumPy array.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L498-L500)

### scope_profiler.region_profiler.PerfEventProfileRegion.get_end_times_numpy

*method*

```python
def get_end_times_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return end times offset by the run's start time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L584-L586)

### scope_profiler.region_profiler.PerfEventProfileRegion.get_start_times_numpy

*method*

```python
def get_start_times_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return start times offset by the run's start time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L588-L590)

### scope_profiler.region_profiler.PerfEventProfileRegion.mark_written

*method*

```python
def mark_written() -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Record that everything buffered so far has been handed to finalize().

Called by ``finalize()`` once the data has been copied out, so that a
second run in the same process reports only its own events instead of
re-reporting the first run's. The timestamp buffer rewinds (the arrays
are reused; anything past ``ptr`` is unread scratch), while
``num_calls`` keeps counting for the lifetime of the process — it is
the in-memory view of the region, which callers inspect after
``finalize()``.

A call still running has a slot reserved that finalize() did not copy
out, so it must survive the rewind. It is moved to the front of the
buffer rather than pinning everything behind it: leaving the whole
buffer in place would make the next finalize() re-report every
completed call sitting below it, with a second set of call ids.

The one case that still cannot rewind is a call entered through the
decorator form, which keeps its slot index in the wrapper's own frame
where nothing can remap it. Recognisable because such a slot is open
without appearing in ``_scope_ptr_stack``. There the buffer stays put
and the slots already copied out are recorded instead, so the next
finalize() skips them rather than reporting those calls again.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L545-L582)

### scope_profiler.region_profiler.PerfEventProfileRegion.open_slots

*method*

```python
def open_slots() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Buffer slots whose call is still running, in ascending order.

A slot is open until its end time is written, which is what
distinguishes a call in flight from one that has returned. Both region
forms are covered: the context manager writes its start on entry, the
decorator writes nothing until the call returns.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L502-L512)

### scope_profiler.region_profiler.PerfEventProfileRegion.set_source

*method*

```python
def set_source(filename, lineno, text) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Record where this region is defined, the first time it is called.

First writer wins: a region name reused at more than one call site
keeps only the first location, matching how their timings are already
pooled together under one name (see issue #161).

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L419-L430)

## scope_profiler.region_profiler.ThreadedProfileRegion

*class*

```python
class ThreadedProfileRegion(BaseProfileRegion)
```

Bases: `scope_profiler.region_profiler.BaseProfileRegion`

Region that records which thread - and which task - each call ran on.

Selected by ``track_threads=True``. Two things change against
:class:`TimeOnlyProfileRegion`:

* every thread gets its own buffers and its own scope stack, so
  concurrent calls no longer overwrite each other's reserved slots or
  close each other's scopes;
* each recorded call carries the lane it ran on, so the nesting
  reconstruction can group calls into stacks that really are stacks (see
  :func:`~scope_profiler.concurrency.lane_ids`).

With ``track_async=True`` a call additionally carries the id of the
asyncio task or greenlet it ran in, and the time that task spent suspended
*inside* the call - the await time of that one call, as opposed to the
task's total.

The per-call cost over :class:`TimeOnlyProfileRegion` is one thread-local
lookup plus, in async mode, two integer reads off the current task record.
Nothing here allocates or locks per call.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L1276-L1499)

### scope_profiler.region_profiler.ThreadedProfileRegion.buffer_limit

*attribute* · *instance attribute*

```python
buffer_limit = config.buffer_limit
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L388-L388)

### scope_profiler.region_profiler.ThreadedProfileRegion.capacity

*attribute* · *instance attribute*

```python
capacity = self.buffer_limit
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L390-L390)

### scope_profiler.region_profiler.ThreadedProfileRegion.config

*attribute* · *instance attribute*

```python
config = config
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L366-L366)

### scope_profiler.region_profiler.ThreadedProfileRegion.end_times

*attribute* · *instance attribute*

```python
end_times = np.zeros(self.capacity, dtype=np.int64)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L392-L392)

### scope_profiler.region_profiler.ThreadedProfileRegion.ptr

*attribute* · *instance attribute*

```python
ptr = 0
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L387-L387)

### scope_profiler.region_profiler.ThreadedProfileRegion.region_name

*attribute* · *instance attribute*

```python
region_name = region_name
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L365-L365)

### scope_profiler.region_profiler.ThreadedProfileRegion.source_file

*attribute* · *instance attribute*

```python
source_file = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L415-L415)

### scope_profiler.region_profiler.ThreadedProfileRegion.source_lineno

*attribute* · *instance attribute*

```python
source_lineno = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L416-L416)

### scope_profiler.region_profiler.ThreadedProfileRegion.source_text

*attribute* · *instance attribute*

```python
source_text = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L417-L417)

### scope_profiler.region_profiler.ThreadedProfileRegion.start_times

*attribute* · *instance attribute*

```python
start_times = np.empty(self.capacity, dtype=np.int64)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L391-L391)

### scope_profiler.region_profiler.ThreadedProfileRegion.tags

*attribute* · *instance attribute*

```python
tags = tuple(tags)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L367-L367)

### scope_profiler.region_profiler.ThreadedProfileRegion.num_calls

*property*

```python
num_calls: int
```

Times this region was entered, over every thread, for the process.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L1332-L1335)

### scope_profiler.region_profiler.ThreadedProfileRegion.threads

*property*

```python
threads: list
```

Thread records that have entered this region, in index order.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L1338-L1342)

### scope_profiler.region_profiler.ThreadedProfileRegion.has_source

*property*

```python
has_source: bool
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Whether this region's call-site source was captured.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L433-L435)

### scope_profiler.region_profiler.ThreadedProfileRegion.closed_slots

*method*

```python
def closed_slots()
```

Not meaningful per lane; :meth:`snapshot_arrays` applies the mask.

None, as the base class means it: every slot qualifies, and there is
no mask for a caller to apply. A threaded region keeps no buffers of
its own, so there is nothing here to mask in the first place.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L1478-L1485)

### scope_profiler.region_profiler.ThreadedProfileRegion.mark_written

*method*

```python
def mark_written() -> None
```

Rewind every lane, keeping calls that are still running.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L1487-L1492)

### scope_profiler.region_profiler.ThreadedProfileRegion.open_slots

*method*

```python
def open_slots() -> np.ndarray
```

Slots still running, over every lane. For diagnostics only.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L1472-L1476)

### scope_profiler.region_profiler.ThreadedProfileRegion.snapshot_arrays

*method*

```python
def snapshot_arrays()
```

This run's completed calls, concatenated over every thread.

Returns
-------
tuple or None
    ``(start_times, end_times, None, None, None, thread_ids,
    task_ids, await_ns)`` in nanoseconds, laid out on the snapshot
    tuple :meth:`ProfileManager._snapshot_regions` documents, or None
    when this region recorded nothing since the last ``finalize()``.
    ``task_ids`` and ``await_ns`` are None unless async tracking is on.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L1422-L1470)

### scope_profiler.region_profiler.ThreadedProfileRegion.wrap

*method*

```python
def wrap(func)
```

Wrap a function so its calls are recorded on the caller's thread.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L1406-L1419)

### scope_profiler.region_profiler.ThreadedProfileRegion.add_function

*method*

```python
def add_function(func) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Register a function for profiling. No-op except in LineProfilerRegion.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L592-L593)

### scope_profiler.region_profiler.ThreadedProfileRegion.append

*method*

```python
def append(start: float, end: float) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Append a start/end time pair to the buffer, growing it if needed.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L479-L486)

### scope_profiler.region_profiler.ThreadedProfileRegion.get_durations_numpy

*method*

```python
def get_durations_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return durations (end - start) for buffered entries as a NumPy array.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L498-L500)

### scope_profiler.region_profiler.ThreadedProfileRegion.get_end_times_numpy

*method*

```python
def get_end_times_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return end times offset by the run's start time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L584-L586)

### scope_profiler.region_profiler.ThreadedProfileRegion.get_start_times_numpy

*method*

```python
def get_start_times_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return start times offset by the run's start time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L588-L590)

### scope_profiler.region_profiler.ThreadedProfileRegion.set_source

*method*

```python
def set_source(filename, lineno, text) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Record where this region is defined, the first time it is called.

First writer wins: a region name reused at more than one call site
keeps only the first location, matching how their timings are already
pooled together under one name (see issue #161).

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L419-L430)

## scope_profiler.region_profiler.TimeOnlyProfileRegion

*class*

```python
class TimeOnlyProfileRegion(BaseProfileRegion)
```

Bases: `scope_profiler.region_profiler.BaseProfileRegion`

Region that records timing, collected once at the end of the run.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L625-L669)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.buffer_limit

*attribute* · *instance attribute*

```python
buffer_limit = config.buffer_limit
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L388-L388)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.capacity

*attribute* · *instance attribute*

```python
capacity = self.buffer_limit
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L390-L390)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.config

*attribute* · *instance attribute*

```python
config = config
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L366-L366)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.end_times

*attribute* · *instance attribute*

```python
end_times = np.zeros(self.capacity, dtype=np.int64)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L392-L392)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.ptr

*attribute* · *instance attribute*

```python
ptr = 0
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L387-L387)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.region_name

*attribute* · *instance attribute*

```python
region_name = region_name
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L365-L365)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.source_file

*attribute* · *instance attribute*

```python
source_file = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L415-L415)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.source_lineno

*attribute* · *instance attribute*

```python
source_lineno = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L416-L416)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.source_text

*attribute* · *instance attribute*

```python
source_text = None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L417-L417)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.start_times

*attribute* · *instance attribute*

```python
start_times = np.empty(self.capacity, dtype=np.int64)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L391-L391)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.tags

*attribute* · *instance attribute*

```python
tags = tuple(tags)
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L367-L367)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.has_source

*property*

```python
has_source: bool
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Whether this region's call-site source was captured.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L433-L435)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.num_calls

*property*

```python
num_calls: int
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Times this region was entered, for the lifetime of the process.

Derived rather than counted: the slots in use (``ptr``) plus whatever
earlier finalize() calls already copied out. Keeping it out of
``__enter__`` removes an attribute write from every recorded call.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L489-L496)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.wrap

*method*

```python
def wrap(func)
```

Wrap a function to measure its execution time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L628-L650)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.add_function

*method*

```python
def add_function(func) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Register a function for profiling. No-op except in LineProfilerRegion.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L592-L593)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.append

*method*

```python
def append(start: float, end: float) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Append a start/end time pair to the buffer, growing it if needed.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L479-L486)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.closed_slots

*method*

```python
def closed_slots() -> np.ndarray | None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Mask of buffered slots this finalize() should copy out.

A slot qualifies once its end time is written and it has not already
gone out with an earlier finalize(). None - the usual case - means
every slot qualifies and the caller can skip the mask entirely.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L514-L526)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.get_durations_numpy

*method*

```python
def get_durations_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return durations (end - start) for buffered entries as a NumPy array.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L498-L500)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.get_end_times_numpy

*method*

```python
def get_end_times_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return end times offset by the run's start time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L584-L586)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.get_start_times_numpy

*method*

```python
def get_start_times_numpy() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Return start times offset by the run's start time.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L588-L590)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.mark_written

*method*

```python
def mark_written() -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Record that everything buffered so far has been handed to finalize().

Called by ``finalize()`` once the data has been copied out, so that a
second run in the same process reports only its own events instead of
re-reporting the first run's. The timestamp buffer rewinds (the arrays
are reused; anything past ``ptr`` is unread scratch), while
``num_calls`` keeps counting for the lifetime of the process — it is
the in-memory view of the region, which callers inspect after
``finalize()``.

A call still running has a slot reserved that finalize() did not copy
out, so it must survive the rewind. It is moved to the front of the
buffer rather than pinning everything behind it: leaving the whole
buffer in place would make the next finalize() re-report every
completed call sitting below it, with a second set of call ids.

The one case that still cannot rewind is a call entered through the
decorator form, which keeps its slot index in the wrapper's own frame
where nothing can remap it. Recognisable because such a slot is open
without appearing in ``_scope_ptr_stack``. There the buffer stays put
and the slots already copied out are recorded instead, so the next
finalize() skips them rather than reporting those calls again.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L545-L582)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.open_slots

*method*

```python
def open_slots() -> np.ndarray
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Buffer slots whose call is still running, in ascending order.

A slot is open until its end time is written, which is what
distinguishes a call in flight from one that has returned. Both region
forms are covered: the context manager writes its start on entry, the
decorator writes nothing until the call returns.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L502-L512)

### scope_profiler.region_profiler.TimeOnlyProfileRegion.set_source

*method*

```python
def set_source(filename, lineno, text) -> None
```

Inherited from: `scope_profiler.region_profiler.BaseProfileRegion`

Record where this region is defined, the first time it is called.

First writer wins: a region name reused at more than one call site
keeps only the first location, matching how their timings are already
pooled together under one name (see issue #161).

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L419-L430)

## scope_profiler.region_profiler.call_site_source

*function*

```python
def call_site_source(filename: str, lineno: int) -> str | None
```

Source text of the ``with`` block starting at ``lineno`` in ``filename``.

Falls back to just the call-site line when the enclosing ``with``
statement cannot be located (e.g. the file cannot be parsed), so a region
still gets *some* location information rather than none.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L67-L80)

## scope_profiler.region_profiler.function_source

*function*

```python
def function_source(func) -> tuple[str, int, str] | None
```

Source file, starting line and text of a decorated function.

Returns None when the source cannot be recovered (e.g. a function defined
interactively or via ``exec``).

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/region_profiler.py#L83-L94)
