pygx.instrument¶
PyGX's instrumentation sub-packages.
instrument
¶
PyGX's instrumentation sub-packages.
Three private modules back the public namespaces re-exported here:
_loggingis exposed aspg.logging/pygx.instrument.logging— use those names to set/read the project logger._monitoringis exposed aspg.monitoring/pygx.instrument.monitoringfor metric collection._timingis flattened into this package:pg.instrument.TimeItandpg.instrument.timeitare the public surface.
TimeIt
¶
Context manager for timing the execution of a code block.
TimeIt contexts nest per-thread: a context entered inside another
becomes its child, and status() reports elapsed times for the whole
subtree with dot-joined names. Usually created via
pg.timeit.
Source code in pygx/instrument/_timing.py
elapse
property
¶
Returns the elapsed seconds from start to end.
Returns 0 when the context has not started; when it has started but not ended, returns the elapsed time up to now.
Status
dataclass
¶
Status(
name: str,
elapse: float = 0.0,
has_ended: bool = True,
error: ErrorInfo | None = None,
)
Bases: WireConvertible
Status of a single pg.timeit.
merge
¶
Merges the status of two pg.timeit.
Source code in pygx/instrument/_timing.py
StatusSummary
dataclass
¶
StatusSummary(breakdown: dict[str, Entry] = dict())
Bases: WireConvertible
Aggregated summary for repeated calls for pg.timeit.
Entry
dataclass
¶
start
¶
end
¶
Ends timing; returns False if the context had already ended.
Source code in pygx/instrument/_timing.py
status
¶
status() -> dict[str, Status]
Gets the status of all timeit contexts under this context.
Keys are dot-joined context names (e.g. 'job.load' for a child
named 'load' under this context named 'job'); statuses of
same-named children are merged.
Source code in pygx/instrument/_timing.py
timeit
¶
timeit(name: str = '') -> TimeIt
Context manager to time a block of code.
Contexts nest per-thread: entering pg.timeit inside another makes it
a child, and status() on the outer context reports elapsed times for
the whole subtree keyed by dot-joined names.
Example:
with pg.timeit('job') as t:
with pg.timeit('load'):
...
with pg.timeit('compute'):
...
status = t.status()
# status keys: 'job', 'job.load', 'job.compute'.
print({name: s.elapse for name, s in status.items()})
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the timing context, used as (part of) its key in
|
''
|
Returns:
| Type | Description |
|---|---|
TimeIt
|
A |
Source code in pygx/instrument/_timing.py
options: show_root_heading: false show_root_toc_entry: false members_order: source heading_level: 2