From 80100c7c85f28449149a654b1d2af0946e9a12e7 Mon Sep 17 00:00:00 2001 From: Christian Bauer Date: Wed, 7 Aug 2024 12:16:31 +0100 Subject: [PATCH] fix(collector): fix documentation for `ResourceMetricCollector.clear()` function (#132) --- CHANGELOG.md | 1 + nvitop/api/collector.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ca53dd1..3a921702 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fix documentation for the `ResourceMetricCollector.clear()` method by [@MyGodItsFull0fStars](https://github.com/MyGodItsFull0fStars) in [#132](https://github.com/XuehaiPan/nvitop/pull/132). - Gracefully ignore UTF-8 decoding errors by [@XuehaiPan](https://github.com/XuehaiPan). ### Removed diff --git a/nvitop/api/collector.py b/nvitop/api/collector.py index ddd4f7c7..90831279 100644 --- a/nvitop/api/collector.py +++ b/nvitop/api/collector.py @@ -296,7 +296,7 @@ class ResourceMetricCollector: # pylint: disable=too-many-instance-attributes collector.activate(tag='') # alias: start collector.deactivate() # alias: stop - collector.reset(tag='') + collector.clear(tag='') collector.collect() with collector(tag=''): @@ -539,14 +539,14 @@ def context(self, tag: str) -> Generator[ResourceMetricCollector]: __call__ = context # alias for `with collector(tag='')` def clear(self, tag: str | None = None) -> None: - """Reset the metric collection with the given tag. + """Clear the metric collection with the given tag. - If the tag is not specified, reset the current active collection. For nested collections, - the sub-collections will be reset as well. + If the tag is not specified, clear the current active collection. For nested collections, + the sub-collections will be cleared as well. Args: tag (Optional[str]): - The tag to reset. If :data:`None`, the current active collection will be reset. + The tag to clear. If :data:`None`, the current active collection will be reset. Examples: >>> collector = ResourceMetricCollector() @@ -558,12 +558,12 @@ def clear(self, tag: str | None = None) -> None: ... time.sleep(5.0) ... collector.collect() # metrics within the cumulative 10.0s interval ... - ... collector.reset() # reset the active collection + ... collector.clear() # clear the active collection ... time.sleep(5.0) ... collector.collect() # metrics within the 5.0s interval ... ... with collector(tag='batch'): # key prefix -> 'train/batch' - ... collector.reset(tag='train') # reset both 'train' and 'train/batch' + ... collector.clear(tag='train') # clear both 'train' and 'train/batch' """ with self._lock: if self._metric_buffer is None: @@ -585,6 +585,8 @@ def clear(self, tag: str | None = None) -> None: break buffer = buffer.prev # type: ignore[assignment] + reset = clear + def collect(self) -> dict[str, float]: """Get the average resource consumption during collection.""" with self._lock: