diff --git a/README.md b/README.md index 4df359b0d..5ad9b98ef 100755 --- a/README.md +++ b/README.md @@ -112,6 +112,13 @@ scalene_profiler.start() scalene_profiler.stop() ``` +```Python +from scalene.scalene_profiler import enable_profiling + +with enable_profiling(): + # do something +``` +
diff --git a/scalene/scalene_profiler.py b/scalene/scalene_profiler.py index 767d35658..17676740b 100644 --- a/scalene/scalene_profiler.py +++ b/scalene/scalene_profiler.py @@ -67,7 +67,7 @@ Set, Tuple, Union, - cast, + cast, Generator, ) import scalene.scalene_config @@ -147,6 +147,13 @@ def stop() -> None: Scalene.stop() +@contextlib.contextmanager +def enable_profiling() -> Generator[None, None, None]: + """Contextmanager that starts and stops profiling""" + start() + yield + stop() + class Scalene: """The Scalene profiler itself."""