Timing
provide.foundation.utils.timing
¶
TODO: Add module docstring.
Classes¶
Functions¶
timed_block
¶
timed_block(
logger_instance: FoundationLogger,
event_name: str,
layer_keys: dict[str, Any] | None = None,
initial_kvs: dict[str, Any] | None = None,
**extra_kvs: Any
) -> Generator[dict[str, Any], None, None]
Context manager that logs the duration of a code block.
Logs at DEBUG when entering, INFO on success, ERROR on exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger_instance
|
FoundationLogger
|
Logger to use for output |
required |
event_name
|
str
|
Name of the operation being timed |
required |
layer_keys
|
dict[str, Any] | None
|
Semantic layer keys (e.g., llm-specific keys) |
None
|
initial_kvs
|
dict[str, Any] | None
|
Initial key-value pairs to include in logs |
None
|
**extra_kvs
|
Any
|
Additional key-value pairs |
{}
|
Yields:
| Type | Description |
|---|---|
dict[str, Any]
|
A mutable dict that can be updated with additional context |
Example
with timed_block(logger, "database_query") as ctx: ctx["query"] = "SELECT * FROM users" result = db.query("SELECT * FROM users") ctx["rows"] = len(result)