Index
provide.testkit.quality.profiling
¶
Performance profiling and analysis for provide-testkit.
Provides performance profiling analysis using memray, cProfile, and other tools. Integrates with the quality framework for comprehensive performance analysis.
Features: - Memory profiling with memray - CPU profiling with cProfile - Performance regression detection - Integration with quality gates - Configurable profiling options
Usage
Basic memory profiling¶
def test_with_profiling(profiling_fixture): result = profiling_fixture.profile_memory(function, *args) assert result.passed
CPU profiling with quality gates¶
runner = QualityRunner() results = runner.run_with_gates(path, {"profiling": {"max_memory_mb": 100}})
Classes¶
PerformanceProfiler
¶
Performance profiler using memray, cProfile, and tracemalloc.
Provides high-level interface for performance analysis with automatic artifact management and integration with the quality framework.
Initialize performance profiler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any] | None
|
Profiler configuration options |
None
|
Source code in provide/testkit/quality/profiling/profiler.py
Functions¶
generate_report
¶
Generate profiling report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
QualityResult
|
Profiling result |
required |
format
|
str
|
Report format |
'terminal'
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted report |
Source code in provide/testkit/quality/profiling/profiler.py
profile_function
¶
Profile a function's performance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Any]
|
Function to profile |
required |
*args
|
Any
|
Function arguments |
()
|
**kwargs
|
Any
|
Function keyword arguments |
{}
|
Returns:
| Type | Description |
|---|---|
QualityResult
|
QualityResult with profiling data |
Source code in provide/testkit/quality/profiling/profiler.py
report
¶
Generate report from QualityResult (implements QualityTool protocol).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
QualityResult
|
Profiling result |
required |
format
|
str
|
Report format |
'terminal'
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted report |
Source code in provide/testkit/quality/profiling/profiler.py
ProfilingFixture
¶
Bases: BaseQualityFixture
Pytest fixture for performance profiling.
Provides easy access to performance profiling with automatic setup and teardown. Integrates with the quality framework fixtures.
Initialize profiling fixture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any] | None
|
Profiler configuration |
None
|
artifact_dir
|
Path | None
|
Directory for artifacts |
None
|
Source code in provide/testkit/quality/profiling/fixture.py
Functions¶
assert_performance
¶
assert_performance(
func: Callable[..., Any],
max_memory_mb: float | None = None,
max_execution_time: float | None = None,
min_score: float | None = None,
*args: Any,
**kwargs: Any
) -> None
Assert performance requirements for a function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Any]
|
Function to test |
required |
max_memory_mb
|
float | None
|
Maximum memory usage in MB |
None
|
max_execution_time
|
float | None
|
Maximum execution time in seconds |
None
|
min_score
|
float | None
|
Minimum performance score |
None
|
*args
|
Any
|
Function arguments |
()
|
**kwargs
|
Any
|
Function keyword arguments |
{}
|
Raises:
| Type | Description |
|---|---|
AssertionError
|
If performance requirements are not met |
Source code in provide/testkit/quality/profiling/fixture.py
benchmark_function
¶
benchmark_function(
func: Callable[..., Any],
iterations: int = 100,
*args: Any,
**kwargs: Any
) -> dict[str, Any]
Benchmark a function over multiple iterations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Any]
|
Function to benchmark |
required |
iterations
|
int
|
Number of iterations to run |
100
|
*args
|
Any
|
Function arguments |
()
|
**kwargs
|
Any
|
Function keyword arguments |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Benchmark results with statistics |
Source code in provide/testkit/quality/profiling/fixture.py
generate_report
¶
Generate profiling report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
format
|
str
|
Report format (terminal, json) |
'terminal'
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted report |
Source code in provide/testkit/quality/profiling/fixture.py
profile_cpu
¶
Profile CPU usage only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Any]
|
Function to profile |
required |
*args
|
Any
|
Function arguments |
()
|
**kwargs
|
Any
|
Function keyword arguments |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
CPU profiling results |
Source code in provide/testkit/quality/profiling/fixture.py
profile_function
¶
Profile a function's performance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Any]
|
Function to profile |
required |
*args
|
Any
|
Function arguments |
()
|
**kwargs
|
Any
|
Function keyword arguments |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Profiling results as dict |
Source code in provide/testkit/quality/profiling/fixture.py
profile_memory
¶
Profile memory usage only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Any]
|
Function to profile |
required |
*args
|
Any
|
Function arguments |
()
|
**kwargs
|
Any
|
Function keyword arguments |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Memory profiling results |