Classes
HasStats
Protocol for components that expose observability stats.
Components implementing this protocol can…
HasStats
Protocol for components that expose observability stats.
Components implementing this protocol can have their stats displayed automatically when phases exceed performance thresholds.
ProtocolAttributes
| Name | Type | Description |
|---|---|---|
last_stats |
ComponentStats | None |
ComponentStats
dataclass
Standardized stats container for any build component.
Provides a uniform interface for tracking:
-…
ComponentStats
dataclass Standardized stats container for any build component.
Provides a uniform interface for tracking:
- Processing counts (total, processed, skipped by reason)
- Cache effectiveness (hits, misses, hit rate)
- Sub-operation timings (analyze, render, validate, etc.)
- Custom metrics (component-specific values)
Attributes
| Name | Type | Description |
|---|---|---|
items_total |
int |
Total items to process |
items_processed |
int |
Items actually processed |
items_skipped |
dict[str, int] |
Dict of skip reasons and counts (e.g., {"autodoc": 450, "draft": 3}) |
cache_hits |
int |
Number of cache hits (if applicable) |
cache_misses |
int |
Number of cache misses (if applicable) |
sub_timings |
dict[str, float] |
Dict of sub-operation names to duration_ms |
metrics |
dict[str, int | float | str] |
Custom metrics (component-specific, e.g., {"pages_per_sec": 375}) |
Methods 5
cache_hit_rate
property
Cache hit rate as percentage (0-100).
cache_hit_rate
property def cache_hit_rate(self) -> float
Cache hit rate as percentage (0-100).
Returns
Percentage of cache hits, or 0.0 if no cache operations.float
—
skip_rate
property
Skip rate as percentage (0-100).
skip_rate
property def skip_rate(self) -> float
Skip rate as percentage (0-100).
Returns
Percentage of items skipped, or 0.0 if no items.float
—
total_skipped
property
Total number of skipped items across all reasons.
total_skipped
property def total_skipped(self) -> int
Total number of skipped items across all reasons.
Returns
int
format_summary
Format stats for CLI output.
Produces a compact, informative summary suitable …
format_summary
def format_summary(self, name: str = '') -> str
Format stats for CLI output.
Produces a compact, informative summary suitable for terminal display. Only includes sections with actual data.
Parameters 1
name |
str |
Component name prefix (e.g., "Directives", "Links") |
Returns
Formatted string like "processed=80/100 | skipped=[autodoc=450] | cache=80/80 (100%)"str
—
to_log_context
Convert to flat dict for structured logging.
Flattens nested data structures f…
to_log_context
def to_log_context(self) -> dict[str, int | float | str]
Convert to flat dict for structured logging.
Flattens nested data structures for log aggregation systems.
Returns
Flat dictionary suitable for structured logging kwargs.dict[str, int | float | str]
—
Functions
format_phase_stats
Format stats for a slow phase, if applicable.
Returns formatted stats string only if the phase exc…
format_phase_stats
def format_phase_stats(phase_name: str, duration_ms: float, component: HasStats | None, slow_threshold_ms: float = 1000) -> str | None
Format stats for a slow phase, if applicable.
Returns formatted stats string only if the phase exceeded the threshold AND the component has stats available.
Parameters 4
| Name | Type | Default | Description |
|---|---|---|---|
phase_name |
str |
— | Name of the phase (e.g., "Directives", "Links") |
duration_ms |
float |
— | How long the phase took |
component |
HasStats | None |
— | Component with HasStats protocol (or None) |
slow_threshold_ms |
float |
1000 |
Threshold for considering a phase "slow" |
Returns
Formatted stats string, or None if phase was fast or no stats available.str | None
—