Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add context-manager for easier of use #174

Open
alex-ber opened this issue Jul 11, 2024 · 1 comment
Open

Please add context-manager for easier of use #174

alex-ber opened this issue Jul 11, 2024 · 1 comment

Comments

@alex-ber
Copy link

alex-ber commented Jul 11, 2024

This will be less error-prone for your clients.
This is my implementation.

import yappi
import contextlib


@contextlib.contextmanager
def yappi_profiler(stats_file_path, stats_format_type='callgrind'):
    yappi.start()
    try:
        yield
    finally:
        yappi.stop()
        yappi.get_func_stats() \
            .save(stats_file_path, type=stats_format_type)
        yappi.clear_stats()


@contextlib.asynccontextmanager
async def ayappi_profiler(stats_file_path, stats_format_type='callgrind):
    yappi.start()
    try:
        yield
    finally:
        yappi.stop()
        yappi.get_func_stats() \
            .save(stats_file_path, type=stats_format_type)
        yappi.clear_stats()
@sumerc
Copy link
Owner

sumerc commented Jul 19, 2024

I am up for it if you can implement this + some tests around this. There might be some naming changes required as well since there is also get_thread_stats..etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants