Skip to content

Commit

Permalink
fix(collector): fix documentation for `ResourceMetricCollector.clear(…
Browse files Browse the repository at this point in the history
…)` function (#132)
  • Loading branch information
MyGodItsFull0fStars committed Aug 7, 2024
1 parent 61add41 commit 80100c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions nvitop/api/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class ResourceMetricCollector: # pylint: disable=too-many-instance-attributes
collector.activate(tag='<tag>') # alias: start
collector.deactivate() # alias: stop
collector.reset(tag='<tag>')
collector.clear(tag='<tag>')
collector.collect()
with collector(tag='<tag>'):
Expand Down Expand Up @@ -539,14 +539,14 @@ def context(self, tag: str) -> Generator[ResourceMetricCollector]:
__call__ = context # alias for `with collector(tag='<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()
Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 80100c7

Please sign in to comment.