Skip to content

feat: Add reset_stats method to LineProfiler for resetting accumulated profiling data #322

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hidva
Copy link

@hidva hidva commented Mar 12, 2025

This PR introduces a new method reset_stats() to the LineProfiler class, allowing users to reset internal profiling statistics without recreating the profiler instance. Use Case:

start_ts = time.monotonic()
self._line_prof.enable()
# logic 
self._line_prof.disable()
end_ts = time.monotonic()
self_prepare_us = (end_ts - start_ts) * 1e6
if self_prepare_us >= 3 * 1000:  # 3ms
    profstat = self._line_prof.get_stats()
    logger.info(
        "dur_us={} stats={} stats.unit={}",
        self_prepare_us,
        profstat.timings,
        profstat.unit,
    )
self._line_prof.reset_stats()

@Erotemic
Copy link
Member

It seems like this feature could be useful. The function will need a docstring that describes what it does. It will also be important to add unit tests for the new feature.

@hidva
Copy link
Author

hidva commented Mar 13, 2025

It seems like this feature could be useful. The function will need a docstring that describes what it does. It will also be important to add unit tests for the new feature.

Added docstring and unit tests.

@Erotemic
Copy link
Member

LGTM, please rebase on main and add an entry in CHANGELOG.rst

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

Successfully merging this pull request may close these issues.

2 participants