Skip to content

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

@Erotemic
Copy link
Member

Is this still needed?

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