Classes
TemplateTimings
dataclass
Timing statistics for a single template.
TemplateTimings
dataclass Timing statistics for a single template.
Attributes
| Name | Type | Description |
|---|---|---|
name |
str |
|
render_times |
list[float] |
Methods 5
count
property
Number of times template was rendered.
count
property def count(self) -> int
Number of times template was rendered.
Returns
int
total_ms
property
Total render time in milliseconds.
total_ms
property def total_ms(self) -> float
Total render time in milliseconds.
Returns
float
avg_ms
property
Average render time in milliseconds.
avg_ms
property def avg_ms(self) -> float
Average render time in milliseconds.
Returns
float
min_ms
property
Minimum render time in milliseconds.
min_ms
property def min_ms(self) -> float
Minimum render time in milliseconds.
Returns
float
max_ms
property
Maximum render time in milliseconds.
max_ms
property def max_ms(self) -> float
Maximum render time in milliseconds.
Returns
float
FunctionTimings
dataclass
Timing statistics for a template function.
FunctionTimings
dataclass Timing statistics for a template function.
Attributes
| Name | Type | Description |
|---|---|---|
name |
str |
|
call_times |
list[float] |
Methods 3
count
property
Number of times function was called.
count
property def count(self) -> int
Number of times function was called.
Returns
int
total_ms
property
Total execution time in milliseconds.
total_ms
property def total_ms(self) -> float
Total execution time in milliseconds.
Returns
float
avg_ms
property
Average execution time in milliseconds.
avg_ms
property def avg_ms(self) -> float
Average execution time in milliseconds.
Returns
float
TemplateProfiler
Collects and reports template rendering performance data.
Thread-safe implementation supports para…
TemplateProfiler
Collects and reports template rendering performance data.
Thread-safe implementation supports parallel builds.
Methods 8
enable
Enable profiling.
enable
def enable(self) -> None
Enable profiling.
disable
Disable profiling.
disable
def disable(self) -> None
Disable profiling.
is_enabled
Check if profiling is enabled.
is_enabled
def is_enabled(self) -> bool
Check if profiling is enabled.
Returns
bool
start_template
Mark start of template render.
start_template
def start_template(self, template_name: str) -> None
Mark start of template render.
Parameters 1
template_name |
str |
Name of template being rendered |
end_template
Mark end of template render and record timing.
end_template
def end_template(self, template_name: str) -> None
Mark end of template render and record timing.
Parameters 1
template_name |
str |
Name of template that finished rendering |
record_function_call
Record a template function call timing.
record_function_call
def record_function_call(self, func_name: str, duration: float) -> None
Record a template function call timing.
Parameters 2
func_name |
str |
Name of the function |
duration |
float |
Execution time in seconds |
get_report
Generate profiling report.
get_report
def get_report(self) -> dict[str, Any]
Generate profiling report.
Returns
Dictionary with template and function timing statisticsdict[str, Any]
—
reset
Clear all collected timing data.
reset
def reset(self) -> None
Clear all collected timing data.
Internal Methods 1
__init__
Initialize the profiler.
__init__
def __init__(self) -> None
Initialize the profiler.
ProfiledTemplate
Wrapper around Jinja2 Template that adds render timing.
Delegates all attribute access to the wrap…
ProfiledTemplate
Wrapper around Jinja2 Template that adds render timing.
Delegates all attribute access to the wrapped template while intercepting render() calls for profiling.
Methods 1
render
Render template with timing instrumentation.
render
def render(self, *args: Any, **kwargs: Any) -> str
Render template with timing instrumentation.
Returns
Rendered template stringstr
—
Internal Methods 2
__init__
Initialize the profiled template.
__init__
def __init__(self, template: Template, profiler: TemplateProfiler) -> None
Initialize the profiled template.
Parameters 2
template |
Template |
Jinja2 Template to wrap |
profiler |
TemplateProfiler |
TemplateProfiler for recording timings |
__getattr__
Delegate attribute access to wrapped template.
__getattr__
def __getattr__(self, name: str) -> Any
Delegate attribute access to wrapped template.
Parameters 1
name |
str |
Returns
Any
Functions
profile_function
Decorator factory for profiling template functions.
profile_function
def profile_function(profiler: TemplateProfiler, func_name: str) -> Callable[[Callable[P, R]], Callable[P, R]]
Decorator factory for profiling template functions.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
profiler |
TemplateProfiler |
— | TemplateProfiler instance |
func_name |
str |
— | Name to record for this function |
Returns
Decorator that wraps function with timingCallable[[Callable[P, R]], Callable[P, R]]
—
format_profile_report
Format profiling report for CLI output.
format_profile_report
def format_profile_report(report: dict[str, Any], top_n: int = 20) -> str
Format profiling report for CLI output.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
report |
dict[str, Any] |
— | Profiling report from TemplateProfiler.get_report() |
top_n |
int |
20 |
Number of top items to show per category |
Returns
Formatted report string for displaystr
—
get_profiler
Get the global template profiler instance.
get_profiler
def get_profiler() -> TemplateProfiler | None
Get the global template profiler instance.
Returns
TemplateProfiler | None
enable_profiling
Enable template profiling globally.
enable_profiling
def enable_profiling() -> TemplateProfiler
Enable template profiling globally.
Returns
The global TemplateProfiler instanceTemplateProfiler
—
disable_profiling
Disable template profiling globally.
disable_profiling
def disable_profiling() -> None
Disable template profiling globally.