Feature: Asynchronous Profiling Support
Description
Extend SmartProfiler to support profiling of asynchronous code (e.g., async def functions, asyncio tasks). Add decorators and context managers that work with async/await syntax, measuring execution time, I/O waits, and other metrics in async contexts.
Why This is Needed
Modern Python applications, especially web servers (e.g., FastAPI, aiohttp), heavily rely on asynchronous programming. Currently, SmartProfiler only supports synchronous code, limiting its usability in async environments. Adding async support will make the library more versatile and appealing to developers working on async projects.
Proposed Implementation
- Add async versions of profiling decorators (e.g.,
profile_async_function) and context managers (e.g., async_profile_block) to BaseProfiler.
- Update each profiler (
CPUProfiler, DiskProfiler, etc.) to support async profiling:
- Use
asyncio.get_running_loop().time() for timing in async contexts.
- Ensure thread-safety for async operations.
- Add unit tests for async profiling scenarios using
asyncio.
- Update
examples_general_usage.py to include an async profiling example (e.g., profiling an async HTTP request with aiohttp).
Acceptance Criteria
Complexity
High (requires handling async context managers, integrating with asyncio, and ensuring thread-safety).
User Value
High (broadens applicability to async applications).
Related Issues
Additional Notes
- Test with popular async frameworks like
aiohttp and FastAPI to ensure compatibility.
- Consider adding async-specific metrics (e.g., I/O wait time) in future releases.
Feature: Asynchronous Profiling Support
Description
Extend
SmartProfilerto support profiling of asynchronous code (e.g.,async deffunctions,asynciotasks). Add decorators and context managers that work withasync/awaitsyntax, measuring execution time, I/O waits, and other metrics in async contexts.Why This is Needed
Modern Python applications, especially web servers (e.g., FastAPI, aiohttp), heavily rely on asynchronous programming. Currently,
SmartProfileronly supports synchronous code, limiting its usability in async environments. Adding async support will make the library more versatile and appealing to developers working on async projects.Proposed Implementation
profile_async_function) and context managers (e.g.,async_profile_block) toBaseProfiler.CPUProfiler,DiskProfiler, etc.) to support async profiling:asyncio.get_running_loop().time()for timing in async contexts.asyncio.examples_general_usage.pyto include an async profiling example (e.g., profiling an async HTTP request withaiohttp).Acceptance Criteria
async deffunction using a decorator (e.g.,@cpu_profiler.profile_async_function).async with cpu_profiler.async_profile_block("task"):).README.mdwith an async profiling example.Complexity
High (requires handling async context managers, integrating with
asyncio, and ensuring thread-safety).User Value
High (broadens applicability to async applications).
Related Issues
Additional Notes
aiohttpandFastAPIto ensure compatibility.